package top.tenebrous.yzl.im.factory.message;

import org.springframework.stereotype.Component;
import top.tenebrous.yzl.im.enums.MessageType;
import top.tenebrous.yzl.im.handler.MessageHandler;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author yazhang6
 */
@Component
public class ChatMessageFactory implements MessageFactory{

    private Map<MessageType, MessageHandler> MESSAGE_MAP = new ConcurrentHashMap<>();

    @Override
    public void register(MessageType messageType, MessageHandler messageHandler) {
        MESSAGE_MAP.put(messageType, messageHandler);
    }

    @Override
    public MessageHandler getInstance(MessageType messageType) {
        return MESSAGE_MAP.get(messageType);
    }
}
